{{- $name := .Chart.Name }}
{{- $globalAnnotationsCheck := include "global.annotations.check" . }}
{{- range $index, $val := .Values.items }}
{{- if not (empty $val.containers) }}
{{- range $Index, $Containers := $val.containers }}
{{- if and $Containers.configMap $Containers.configMap.enabled $Containers.configMap.data }}
apiVersion: v1
kind: ConfigMap
metadata:
{{- if or $val.annotations $globalAnnotationsCheck }}
  annotations:
{{- if and $val.annotations (not (eq $val.type "global")) }}
{{- toYaml $val.annotations | nindent 4 }}
{{- end }}
{{- if $globalAnnotationsCheck }}
{{- range $Index, $Val := $.Values.items }}
{{- if eq $Val.type "global" }}
{{- toYaml $Val.annotations | nindent 4 }}
{{- end }}{{- end }}{{- end }}
{{- end }}
  labels:
    app: {{ $name }}
    tier: {{ $val.name | default (print $name) }}-config
  name: {{ $Containers.configMap.name | default (print $name "-config") }}
data:
  {{- range $key, $value := $Containers.configMap.data }}{{- if $value }}
  {{- printf "%v: %v" $key (printf "%v" $value | quote) | nindent 2 }}
  {{- end }}{{- end }}
{{ print "---" }}
{{- end }}{{- end }}{{- end }}{{- end }}